﻿@model Sykj.Entity.Advertiseposition
@{
    ViewData["Title"] = "编辑广告位";
    Layout = "~/Areas/Manager/Views/Shared/_Layout.cshtml";
}
<div class="layui-bg">
    <form class="layui-form" style="padding: 20px 30px 0 0;">
        <div class="layui-form-item">
            <label class="layui-form-label">显示类型</label>
            <div class="layui-input-block">
                <input type="hidden" name="AdvPositionId" asp-for="AdvPositionId" />
                <select id="ShowType" asp-for="ShowType" lay-verify="required">
                    <option value="0">纵向平铺</option>
                    <option value="1">横向平铺</option>
                    <option value="2">层叠显示</option>
                    <option value="3">交替显示</option>
                    <option value="4">自定义广告代码</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">广告位名称</label>
            <div class="layui-input-block">
                <input type="text" asp-for="AdvPositionName" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item" style="display:none" id="RepeatColumns">
            <label class="layui-form-label">行显示个数</label>
            <div class="layui-input-block">
                <input type="text" name="RepeatColumns" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="display:none" id="AdvHtml">
            <label class="layui-form-label">广告位内容</label>
            <div class="layui-input-block">
                <textarea name="AdvHtml"  class="layui-textarea"  style="height:70px;width:100%"></textarea>
            </div>
        </div>
        <div class="layui-form-item" pane="">
            <div class="layui-input-block">
                <input type="checkbox" id="IsOneCheckBox" lay-skin="primary" title="循环显示" lay-filter="isOne">
                <input type='hidden' name='TimeInterval' asp-for="TimeInterval" placeholder='循环间隔' id="temporaryInput" class='temporaryInput layui-input' style='display:inline-block;width:75px;' />
                <input type="hidden" name="IsOne" id="IsOne" asp-for="IsOne" />
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="edit" id="submit" type="button">提交</button>
                <button id="close" type="button" class="layui-btn layui-btn-primary">关闭</button>
            </div>
        </div>
    </form>
</div>
@section scriptsfeet
    {
    <script type="text/javascript">
        layui.config({
            base: '/layuiadmin/' //自定义模块路径
        }).use(['form', 'layer', 'sykjwh'], function () {
            var $ = layui.$, form = layui.form, sykjwh = layui.sykjwh;

            form.on('checkbox(isOne)', function (data) {
                $("#temporaryInput").attr("type", "hidden");
                if (data.elem.checked) {//判断复选框是否被选中
                    $("#IsOne").val(true);//如果选中则修改IsOne的value为true
                    $("#temporaryInput").attr("type", "text");
                } else {
                    $("#IsOne").val(false);
                }
            });  


            form.on('select(Select)', function (data) {
                if (data.value == 1) {
                    $("#RepeatColumns").show();
                    $("#AdvHtml").hide();
                } else if (data.value == 4) {
                    $("#RepeatColumns").hide();
                    $("#AdvHtml").show();
                } else {
                    $("#RepeatColumns").hide();
                    $("#AdvHtml").hide();
                }
            });

            $("#close").click(function () {
                sykjwh.close();
            });

            //表单提交
            form.on('submit(edit)', function (obj) {
                //如果循环显示没有被选中，那么将循环间隔设置为0
                if ($("#IsOne").val() == "false") {
                    obj.field.TimeInterval = null;
                    console.log("isone" + $("#IsOne").val());
                }
                sykjwh.save('@Url.Action("AdpositionEdit", "AD", new { area = Constant.AREAMANAGER })', obj.field);
            });

            //初始化页面
            initInfo();

            function initInfo() {
                if ("@Model.IsOne"=="True") {
                    console.log("@Model.IsOne");
                    $("#IsOneCheckBox").attr("checked", "");
                    $("#temporaryInput").attr("type", "text");
                }

                //重新渲染页面
                form.render();
            }
        });
    </script>
}
